<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>centos7相关操作备忘 - Lglspace‘s Blog</title>
  <meta name="renderer" content="webkit" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>

<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">


<meta name="author" content="lglspace" /><meta name="description" content="用户操作 1 2 3 4 5 6 7 8 9 10 # 用户列表文件 cat /etc/passwd/ # 用户组列表文件 cat /etc/group # 查看系统中有哪些用户 cut -d : -f 1 /etc/passwd # 查看可以登录系统的用户 cat /etc/passwd | grep -v /sbin/nologin | cut" /><meta name="keywords" content="lglspace, blog, lgl" />






<meta name="generator" content="Hugo 0.79.0 with theme even" />


<link rel="canonical" href="https://lglspace.cn/post/linux/linux-centos7-relate/" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">



<link href="/sass/main.min.b5a744db6de49a86cadafb3b70f555ab443f83c307a483402259e94726b045ff.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.css" integrity="sha256-7TyXnr2YU040zfSP+rEcz29ggW4j56/ujTPwjMzyqFY=" crossorigin="anonymous">
<link rel="stylesheet" href="/css/even-custom.css">


<meta property="og:title" content="centos7相关操作备忘" />
<meta property="og:description" content="用户操作 1 2 3 4 5 6 7 8 9 10 # 用户列表文件 cat /etc/passwd/ # 用户组列表文件 cat /etc/group # 查看系统中有哪些用户 cut -d : -f 1 /etc/passwd # 查看可以登录系统的用户 cat /etc/passwd | grep -v /sbin/nologin | cut" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://lglspace.cn/post/linux/linux-centos7-relate/" />
<meta property="article:published_time" content="2020-10-23T09:34:28+08:00" />
<meta property="article:modified_time" content="2020-10-23T09:34:28+08:00" />
<meta itemprop="name" content="centos7相关操作备忘">
<meta itemprop="description" content="用户操作 1 2 3 4 5 6 7 8 9 10 # 用户列表文件 cat /etc/passwd/ # 用户组列表文件 cat /etc/group # 查看系统中有哪些用户 cut -d : -f 1 /etc/passwd # 查看可以登录系统的用户 cat /etc/passwd | grep -v /sbin/nologin | cut">
<meta itemprop="datePublished" content="2020-10-23T09:34:28+08:00" />
<meta itemprop="dateModified" content="2020-10-23T09:34:28+08:00" />
<meta itemprop="wordCount" content="780">



<meta itemprop="keywords" content="linux,centos," />
<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="centos7相关操作备忘"/>
<meta name="twitter:description" content="用户操作 1 2 3 4 5 6 7 8 9 10 # 用户列表文件 cat /etc/passwd/ # 用户组列表文件 cat /etc/group # 查看系统中有哪些用户 cut -d : -f 1 /etc/passwd # 查看可以登录系统的用户 cat /etc/passwd | grep -v /sbin/nologin | cut"/>

<!--[if lte IE 9]>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/classlist/1.1.20170427/classList.min.js"></script>
<![endif]-->

<!--[if lt IE 9]>
  <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
<![endif]-->

</head>
<body>
  <div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="/" class="logo">Lglspace</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>
<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    <a href="/">
        <li class="mobile-menu-item">主页</li>
      </a><a href="/post/">
        <li class="mobile-menu-item">归档</li>
      </a><a href="/tags/">
        <li class="mobile-menu-item">标签</li>
      </a><a href="/categories/">
        <li class="mobile-menu-item">分类</li>
      </a>
  </ul>

  


</nav>

  <div class="container" id="mobile-panel">
    <header id="header" class="header">
        <div class="logo-wrapper">
  <a href="/" class="logo">Lglspace</a>
</div>





<nav class="site-navbar">
  <ul id="menu" class="menu">
    <li class="menu-item">
        <a class="menu-item-link" href="/">主页</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/post/">归档</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/tags/">标签</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/categories/">分类</a>
      </li>
  </ul>
</nav>

    </header>

    <main id="main" class="main">
      <div class="content-wrapper">
        <div id="content" class="content">
          <article class="post">
    
    <header class="post-header">
      <h1 class="post-title">centos7相关操作备忘</h1>

      <div class="post-meta">
        <span class="post-time"> 2020-10-23 </span>
        <div class="post-category">
            <a href="/categories/linux/"> linux </a>
            </div>
        
      </div>
    </header>

    <div class="post-toc" id="post-toc">
  <h2 class="post-toc-title">文章目录</h2>
  <div class="post-toc-content always-active">
    <nav id="TableOfContents">
  <ul>
    <li>
      <ul>
        <li><a href="#用户操作">用户操作</a></li>
        <li><a href="#root用户不允许远程登录">ROOT用户不允许远程登录</a></li>
        <li><a href="#安装ifconfig">安装ifconfig</a></li>
        <li><a href="#修改ip地址">修改IP地址</a>
          <ul>
            <li><a href="#动态获取ip">动态获取ip</a></li>
            <li><a href="#设置静态ip地址">设置静态IP地址</a></li>
          </ul>
        </li>
        <li><a href="#时间同步和时区设置">时间同步和时区设置</a></li>
        <li><a href="#修改yum镜像为阿里yum源-mirrorsaliyuncom">修改yum镜像为阿里yum源-mirrors.aliyun.com</a></li>
        <li><a href="#查看端口的占用情况">查看端口的占用情况</a></li>
        <li><a href="#遇到的问题">遇到的问题</a>
          <ul>
            <li><a href="#font-colorredcould-not-resolve-host-mirrorscloudaliyuncscom-unknown-errorfont"><font color=red>Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error</font></a></li>
            <li><a href="#font-colorredno-packagenothing-to-dofont"><font color=red>No package,Nothing to do  </font></a></li>
          </ul>
        </li>
      </ul>
    </li>
  </ul>
</nav>
  </div>
</div>
    <div class="post-content">
      <h2 id="用户操作">用户操作</h2>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 用户列表文件</span>
cat /etc/passwd/
<span class="c1"># 用户组列表文件</span>
cat /etc/group
<span class="c1"># 查看系统中有哪些用户</span>
cut -d : -f <span class="m">1</span> /etc/passwd
<span class="c1"># 查看可以登录系统的用户</span>
cat /etc/passwd <span class="p">|</span> grep -v /sbin/nologin <span class="p">|</span> cut -d : -f <span class="m">1</span>


</code></pre></td></tr></table>
</div>
</div><h2 id="root用户不允许远程登录">ROOT用户不允许远程登录</h2>
<p>vim /etc/ssh/sshd_config 加入一行</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">PermitRootLogin no
</code></pre></td></tr></table>
</div>
</div><p>重启sshd服务</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">service sshd restart
</code></pre></td></tr></table>
</div>
</div><h2 id="安装ifconfig">安装ifconfig</h2>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">yum search ifconfig
yum install net-tools.x86_64 
</code></pre></td></tr></table>
</div>
</div><h2 id="修改ip地址">修改IP地址</h2>
<h3 id="动态获取ip">动态获取ip</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">vi /etc/sysconfig/network-scripts/ifcfg-ens32
</code></pre></td></tr></table>
</div>
</div><p>修改两处：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">bootproto=dhcp
onboot=yes
</code></pre></td></tr></table>
</div>
</div><p>重启网络服务</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">systemctl restart network
</code></pre></td></tr></table>
</div>
</div><h3 id="设置静态ip地址">设置静态IP地址</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">vi /etc/sysconfig/network-scripts/ifcfg-ens32
</code></pre></td></tr></table>
</div>
</div><p>修改两处及添加相关IP信息：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span><span class="lnt">9
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">bootproto=dhcp
onboot=yes

# 在文件最后添加
IPADDR=192.168.12.17
NETMASK=255.255.255.0
GATEWAY=192.168.12.1
DNS1=119.29.29.29
DNS2=8.8.8.8
</code></pre></td></tr></table>
</div>
</div><p>重启网络服务</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">systemctl restart network
</code></pre></td></tr></table>
</div>
</div><h2 id="时间同步和时区设置">时间同步和时区设置</h2>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 安装ntp服务的软件包</span>
sudo yum install ntp
<span class="c1"># 将ntp服务设置为缺省启动</span>
systemctl <span class="nb">enable</span> ntpd
<span class="c1"># 修改启动参数，增加`-g -x`参数，允许ntp服务在系统时间误差较大时也能正常工作</span>
sudo vi /etc/sysconfig/ntpd
<span class="c1"># 启动ntp服务</span>
sudo service ntpd restart
<span class="c1"># 将系统时区改为上海时间 (亦即CST时区)</span>
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
<span class="c1"># 查看时间是否正确</span>
date
</code></pre></td></tr></table>
</div>
</div><h2 id="修改yum镜像为阿里yum源-mirrorsaliyuncom">修改yum镜像为阿里yum源-mirrors.aliyun.com</h2>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1">#首先备份系统自带yum源配置文件/etc/yum.repos.d/CentOS-Base.repo</span>
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
<span class="c1">#查看CentOS系统版本</span>
cat /etc/centos-release
<span class="c1">#下载ailiyun的yum源配置文件到/etc/yum.repos.d/</span>
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
<span class="c1">#清理缓存</span>
yum clean all
<span class="c1">#运行yum makecache生成缓存</span>
yum makecache
</code></pre></td></tr></table>
</div>
</div><h2 id="查看端口的占用情况">查看端口的占用情况</h2>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">netstat -lntp <span class="p">|</span> grep <span class="m">6379</span> 
</code></pre></td></tr></table>
</div>
</div><h2 id="遇到的问题">遇到的问题</h2>
<h3 id="font-colorredcould-not-resolve-host-mirrorscloudaliyuncscom-unknown-errorfont"><font color=red>Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error</font></h3>
<p>1.首先进入 /etc/yum.repos.d 目录备份文件 CentOs-Base.repo,执行</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">cd /etc/yum.repos.d
cp CentOs-Base.repo CentOs-Base.repo.bak
</code></pre></td></tr></table>
</div>
</div><p>2.修改CentOs-Base.repo文件</p>
<p><a href="http://mirrors.cloud.aliyuncs.com/centos/">http://mirrors.cloud.aliyuncs.com/centos/</a>批量替换为 <a href="http://mirrors.aliyun.com/centos">http://mirrors.aliyun.com/centos</a></p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">%s#http://mirrors.cloud.aliyuncs.com/centos/#http://mirrors.aliyun.com/centos#g
%s/$releasever/\/7/g 
</code></pre></td></tr></table>
</div>
</div><p>3、更新镜像源</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback"> yum clean all
 yum makecache 
</code></pre></td></tr></table>
</div>
</div><h3 id="font-colorredno-packagenothing-to-dofont"><font color=red>No package,Nothing to do  </font></h3>
<p>在执行yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils &amp;&amp; scl enable devtoolset-9 bash 时报：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-go" data-lang="go"><span class="p">[</span><span class="nx">root</span><span class="err">@</span><span class="nx">host81</span> <span class="err">~</span><span class="p">]</span><span class="err">#</span> <span class="nx">yum</span> <span class="o">-</span><span class="nx">y</span> <span class="nx">install</span> <span class="nx">devtoolset</span><span class="o">-</span><span class="mi">9</span><span class="o">-</span><span class="nx">gcc</span> <span class="nx">devtoolset</span><span class="o">-</span><span class="mi">9</span><span class="o">-</span><span class="nx">gcc</span><span class="o">-</span><span class="nx">c</span><span class="o">++</span> <span class="nx">devtoolset</span><span class="o">-</span><span class="mi">9</span><span class="o">-</span><span class="nx">binutils</span> <span class="o">&amp;&amp;</span> <span class="nx">scl</span> <span class="nx">enable</span> <span class="nx">devtoolset</span><span class="o">-</span><span class="mi">9</span> <span class="nx">bash</span>
<span class="nx">Loaded</span> <span class="nx">plugins</span><span class="p">:</span> <span class="nx">fastestmirror</span>
<span class="nx">Loading</span> <span class="nx">mirror</span> <span class="nx">speeds</span> <span class="nx">from</span> <span class="nx">cached</span> <span class="nx">hostfile</span>
<span class="nx">No</span> <span class="kn">package</span> <span class="nx">devtoolset</span><span class="o">-</span><span class="mi">9</span><span class="o">-</span><span class="nx">gcc</span> <span class="nx">available</span><span class="p">.</span>
<span class="nx">No</span> <span class="kn">package</span> <span class="nx">devtoolset</span><span class="o">-</span><span class="mi">9</span><span class="o">-</span><span class="nx">gcc</span><span class="o">-</span><span class="nx">c</span><span class="o">++</span> <span class="nx">available</span><span class="p">.</span>
<span class="nx">No</span> <span class="kn">package</span> <span class="nx">devtoolset</span><span class="o">-</span><span class="mi">9</span><span class="o">-</span><span class="nx">binutils</span> <span class="nx">available</span><span class="p">.</span>
<span class="nx">Error</span><span class="p">:</span> <span class="nx">Nothing</span> <span class="nx">to</span> <span class="nx">do</span>
</code></pre></td></tr></table>
</div>
</div><p>在这之前执行下：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">yum -y install centos-release-scl
</code></pre></td></tr></table>
</div>
</div>
    </div>

    <div class="post-copyright">
  <p class="copyright-item">
    <span class="item-title">文章作者</span>
    <span class="item-content">lglspace</span>
  </p>
  <p class="copyright-item">
    <span class="item-title">上次更新</span>
    <span class="item-content">
        2020-10-23
        
    </span>
  </p>
  
  
</div>
<footer class="post-footer">
      <div class="post-tags">
          <a href="/tags/linux/">linux</a>
          <a href="/tags/centos/">centos</a>
          </div>
      <nav class="post-nav">
        <a class="prev" href="/post/linux/linux-sz-rz/">
            <i class="iconfont icon-left"></i>
            <span class="prev-text nav-default">Linux上rz/sz命令的安装</span>
            <span class="prev-text nav-mobile">上一篇</span>
          </a>
        <a class="next" href="/post/redis/redis-install-linux/">
            <span class="next-text nav-default">Redis在Linux上的安装</span>
            <span class="next-text nav-mobile">下一篇</span>
            <i class="iconfont icon-right"></i>
          </a>
      </nav>
    </footer>
  </article>
        </div>
        

  

  

      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="social-links">
      <a href="mailto:lglspace@outlook.com" class="iconfont icon-email" title="email"></a>
  <a href="https://lglspace.cn/index.xml" type="application/rss+xml" class="iconfont icon-rss" title="rss"></a>
</div>

<div class="copyright">
  

  

  <span class="copyright-year">
    &copy; 
    2020 - 
    2021<span class="heart"><i class="iconfont icon-heart"></i></span><span>lglspace</span>
  </span>
</div>

    </footer>

    <div class="back-to-top" id="back-to-top">
      <i class="iconfont icon-up"></i>
    </div>
  </div>
  
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/slideout@1.0.1/dist/slideout.min.js" integrity="sha256-t+zJ/g8/KXIJMjSVQdnibt4dlaDxc9zXr/9oNPeWqdg=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.js" integrity="sha256-XVLffZaxoWfGUEbdzuLi7pwaUJv1cecsQJQqGLe7axY=" crossorigin="anonymous"></script>



<script type="text/javascript" src="/js/main.min.a74e82b84b872f6b028df4e965781ddbba1606f0253b4fad5e4cf3913cf576eb.js"></script>






<script src="/js/site-custom.js"></script>


</body>
</html>
